package cn.kgc.reflect;

import cn.kgc.annotation.Bean;
import cn.kgc.annotation.Value;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;

/**
 * @author: mosin
 * @version: v1.0  2022/10/20
 * 通过反射操作类对象中的注解
 *
 */
public class ReflectDemo07 {

    public static void main(String[] args) {

        ArrayList<String> arrayList  =  new ArrayList<>();

        Class clazz = arrayList.getClass();

        try {
            Field elementData = clazz.getDeclaredField("elementData");

            elementData.setAccessible(true);
            Object[] o = (Object[]) elementData.get(arrayList);
            System.out.println("-----------添加任何元素之前数组的长度--------------");
            System.out.println("length="+o.length);
            System.out.println("-----------添加一个元素之后数组的长度--------------");
            arrayList.add("hello");
            o = (Object[]) elementData.get(arrayList);
            System.out.println("length="+o.length);
            System.out.println("-----------添加第10个元素之后数组的长度--------------");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            arrayList.add("hello");
            o = (Object[]) elementData.get(arrayList);
            System.out.println("length="+o.length);

            System.out.println("-----------添加第11个元素之后数组的长度--------------");
            arrayList.add("hello");
            o = (Object[]) elementData.get(arrayList);
            System.out.println("length="+o.length);

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
